package com.hyjx.framework.uc.subsys;

import com.hyjx.framework.orm.dao.IBaseDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class SubsysServiceImpl implements SubsysService {
    @Resource
    private IBaseDao dao;

    /**
     * 增加
     * @param model
     */

    public boolean add(SubsysModel model) {
        return dao.addObject(model.getModuleName() + ".insert", model);
    }

    /**
     * 更新
     *
     * @param model
     */
    public int update(SubsysModel model) {
        return dao.updateObject(model.getModuleName() + ".update", model);
    }

    /**
     * 删除
     *
     * @param ids
     */
    public int delete(String ids) {
        String[] idArray = ids.split(",");
        for (int i = 0; i < idArray.length; i++) {
            String id = idArray[i];
            if (dao.deleteObject(new SubsysModel().getModuleName() + ".delete", id) < 1) {
                return 0;
            }
        }
        return 1;
    }

    /**
     * 根据id取子系统信息
     *
     * @param id
     */
    public SubsysModel getSubsysById(String id) {
        return (SubsysModel) dao.queryObject(new SubsysModel().getModuleName() + ".getSubsysById", id);
    }

    /**
     * 根据条件取Json string
     */
    public String getSubsys(SubsysModel testModel) {
        return dao.getPageJsonStr(new SubsysModel().getModuleName() + ".getAllSubsys", new SubsysModel().getModuleName() + ".getSubsysNum", testModel);
    }

    /**
     * 取有效子系统信息
     */
    @SuppressWarnings({"unchecked"})
    public List<SubsysModel> getAllSubsys(SubsysModel model) {

        return dao.queryObjectList(model.getModuleName() + ".getSubsys", model);
    }

    @Override
    public List<SubsysModel> getAllSubsysExist(SubsysModel model) {
        return dao.queryObjectList(model.getModuleName() + ".getAllSubsysExist", model);
    }
}